/**
 * @author scylla
 * @version V1.0
 * @Project echo-java-base
 * @Title
 * @Description *
 * @Package concurrent.mthread.synchronizeCodeBlock
 * @Since 2021/8/18 4:03 下午
 */
package concurrent.mthread.synchronizeCodeBlock;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class CriticalSection {
    static void testApproaches(PairManager pm1, PairManager pm2) {
        ExecutorService exec = Executors.newCachedThreadPool();
        PairManipulator pairManipulator1 = new PairManipulator(pm1),
                pairManipulator2 = new PairManipulator(pm2);

        PiarChecker pcheck1 = new PiarChecker(pm1),
                pcheck2 = new PiarChecker(pm2);

        exec.execute(pairManipulator1);
        exec.execute(pairManipulator2);
        exec.execute(pcheck1);
        exec.execute(pcheck2);

        try {
            //等待0.5秒
            TimeUnit.MILLISECONDS.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("pairManipulator1: " + pairManipulator1 + "\n pairManipulator2" + pairManipulator2);
        System.exit(0);


    }

}
